<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>测试</title>
    <link href="/webjars/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <script src="/webjars/sockjs-client/sockjs.min.js"></script>
<body>

<h1>springboot 加强过得 的websocket</h1>
<button onclick="connect()" class="btn btn-danger"> 连接</button>
<button onclick="send()" class="btn btn-danger"> 发送</button>
<button onclick="closz()" class="btn btn-warning"> 关闭</button>
<div id='content' style="background-color: blanchedalmond;color: black;width: 100px;height: 20px">

</div>
</body>
<script type="text/javascript">

    var socket = null;

    if(typeof(WebSocket) == "undefined") {
        alert("您的浏览器不支持WebSocket");
    }

    function connect(){
        // socket = new WebSocket('ws://localhost:8080/originalendpointupdate');
        socket = new SockJS('http://localhost:8080/originalendpointupdate'); //连接上端点(基站)
        console.log(1);
        console.log(socket);
        socket.onmessage = onMessage;
        socket.onerror=onError;
        socket.onclose=onClose;
    }
    function onClose() {
        console.log("关闭连接");
    }
    function onError(event) {
        console.log(event);
    }
    function onMessage(data){
        console.log(data);
        document.getElementById("content").innerText = data.data;
    }
    function send(){
        socket.send('Hell');
    }
    function closz(){
        alert();
        console.log("要关闭了");
        socket.close();
        socket = null;
    }
</script>
</html>